/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mjma_attendance_system;

/**
 *
 * @author JM
 * 
 */
import java.sql.*;
import java.sql.Timestamp;
import java.util.Date;

public class CredentialController
{
    
    public boolean VerifyUserCredentials(String s1,String s2,String s3,String s4)
    {
        int RowCount = 0;
        
        try
        {
         Class.forName("com.mysql.jdbc.Driver");
         String url = "jdbc:mysql://localhost:"+s3+"/"+s4+"";
         java.util.Date date= new java.util.Date();
	 Timestamp CompTimeStmp = new Timestamp(date.getTime());
         System.out.println("System Attempt at:"+ CompTimeStmp );
         
         System.out.println(url);
         System.out.println("SELECT username, password from administrators_list WHERE username = '"+s1+"' AND password = '"+s2+"'");
         
         Connection Conn = DriverManager.getConnection(url,"root","password");
         Statement Insert = Conn.createStatement();
         Statement select = Conn.createStatement();
         ResultSet result;
         Insert.executeUpdate("INSERT into logs_login_history (username,password,port,DBsource,timestamp,status_login) VALUES ('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+CompTimeStmp+"','1' )");
         result = select.executeQuery("SELECT username, password from administrators_list WHERE username = '"+s1+"' AND password = '"+s2+"' ");
         
                 

         ResultSetMetaData rsmd = result.getMetaData();
         
         int Colc = rsmd.getColumnCount();
         
         while(result.next())
         {
             RowCount++;
         }
         
         
         
         
        }
        catch(Exception ex)
        {
           ex.printStackTrace();
        }
        
        if(RowCount==0)
            return false;
        else
        {
       
           System.out.println("User Authenticated.");
               return true;
        }
        }
    
    
    
}
